<?php
class model_user extends spModel
{
	public $pk = "id";
	public $table = "user";
	public $verifier = array(
		"rules" => array(
			'uname' => array( 
				'notnull' => TRUE
			),
		),
		"messages" => array( 
			'uname' => array(
				'notnull' => "User name can't empty"
			),
		)
	);
	public function userlogin($uname, $upass)
	{
		$conditions = array(
			'uname' => $uname,
			'upass' => $upass
		);
		if( $result = $this->find($conditions) ){ 
			spClass('spAcl')->set($result['acl']);
			$_SESSION["userinfo"] = $result;
			return true;
		}else{
			return false;
		}
	}
	public function changeUserPassowrld($user_id, $new_password ) {
		$update_data = array($this->pk=>$user_id,'upass'=>md5($new_password));
		$this->update(array($this->pk=>$user_id), $update_data);
		$_SESSION["userinfo"]['upass'] = md5($new_password);
	}
	public function acljump(){ 
		$language_string = spClass("language_string");
		$url = spUrl("main","login");
		$promote_msg = $language_string->getStr('login_need');
		echo "<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"><script>function sptips(){alert(\"$promote_msg\");location.href=\"{$url}\";}</script></head><body onload=\"sptips()\"></body></html>";
		exit;
	}
	public function apiacljump() {
		$response_data = array('error'=>'need login');
		echo json_encode($response_data);
		exit();
	}
}